package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.DictionaryDetail;
import cn.wolfcode.crm.mapper.DictionaryDetailMapper;
import cn.wolfcode.crm.mapper.DictionaryMapper;
import cn.wolfcode.crm.domain.Dictionary;
import cn.wolfcode.crm.mapper.DictionaryMapper;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictionaryServiceImpl implements IDictionaryService {
    @Autowired
    private DictionaryMapper dictionaryMapper;
    @Autowired
    private DictionaryDetailMapper dictionaryDetailMapper;


    public List<DictionaryDetail> selectDetailsByDicId(Long id) {
        return dictionaryDetailMapper.selectDetialByDictionaryId(id);
    }

    public int deleteByPrimaryKey(Long id) {
        return dictionaryMapper.deleteByPrimaryKey(id);
    }

    public int insert(Dictionary entity) {
        return dictionaryMapper.insert(entity);
    }

    public Dictionary selectByPrimaryKey(Long id) {
        return dictionaryMapper.selectByPrimaryKey(id);
    }

    public List<Dictionary> selectAll() {
        return dictionaryMapper.selectAll();
    }

    public int updateByPrimaryKey(Dictionary entity) {
        return dictionaryMapper.updateByPrimaryKey(entity);
    }

    public PageResult query(QueryObject qo) {
        int totalCount = dictionaryMapper.queryForCount(qo);
        if (totalCount == 0) {
            return new PageResult();
        }
        List<Dictionary> list = dictionaryMapper.queryForList(qo);
        return new PageResult(totalCount, list);
    }
}
